﻿using System;
using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class CountryIdLookupController : LookupController
    {
        private readonly IRepo<Country> repo;

        public CountryIdLookupController(IRepo<Country> repo)
        {
            this.repo = repo;
        }

        [HttpPost]
        public ActionResult Search(string search)
        {
            return View(@"Awesome\LookupList", repo.GetAll().Where(o => o.Name.Containz(search)));
        }

        //returns the text that is going to be set into the textbox near the lookup button 
        public ActionResult Get(int id)
        {      
            return Content((repo.Get(id) ?? new Country()).Name);
        }
    }
}